/**
 * 添加装车站
 * @author xiaoxujs
 */

import { Form, Input, message, Modal } from "antd";
import { FC } from "react";
import { IYckzZyLoadControlAddLoadParams } from "../../../../../type/remoteControl/loadingControlList";
import { postYckzZyLoadControlAddLoad } from "../../../api";

const AddModule: FC<{
    open: boolean,
    handleAddCallback: () => void;
}> = ({
    open,
    handleAddCallback
}) => {
    const [form] = Form.useForm<IYckzZyLoadControlAddLoadParams>();



        const handleOk = async () => {
            const values = await form.validateFields();
            const {code, msg} = await postYckzZyLoadControlAddLoad(values) as {code: number, msg: string};
            if(code === 20000) {
                message.success('添加成功');
                handleCancel();

            }else{
                message.error(msg);
            }
            // postYckzZyLoadControlAddLoad
        };

        const handleCancel = () => {
            form.resetFields();
            handleAddCallback();
        };
        return <Modal title="添加装车站" open={open} onOk={handleOk} onCancel={handleCancel}>
            <Form
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 16 }}
                form={form}
            >
                <Form.Item<IYckzZyLoadControlAddLoadParams>
                    label="装车站名称"
                    name="loadStationName"
                    rules={[{ required: true, message: '请输入装车站名称!' }]}
                >
                    <Input />
                </Form.Item>
            </Form>
        </Modal>
    }

export default AddModule;